<?php

namespace app\admin\controller;

use app\admin\model\AdminRule;
use app\admin\model\Menus;
use think\facade\Db;

class Auth extends Base
{
    /**
     * 获取主菜单
     *
     * @return \think\Response
     */
    public function index()
    {
//        $data =AdminRule::where('pid', 0)->select();
        $data =Menus::where('pid', 0)->select();

        for($i=1;$i<=count($data);$i++){
            $children =Menus::where('pid', $i)->select();
            $data[$i-1]['children'] =  $children;
        }
        return $this->create($data,
            $data->isEmpty() ? '数据不存在' :'数据请求成功',
            201);
    }

    /**
     * 获取次菜单
     *
     * @return \think\Response
     */
    public function getMuem()
    {
        $data =AdminRule::where('pid', 0)->select();
        return $this->create($data,
            $data->isEmpty() ? '数据不存在' :'数据请求成功',
            201);
    }
}